package com.shop.cloud.controller.system;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.shop.cloud.common.mybatis.BaseController;
import com.shop.cloud.domain.system.SysDict;
import com.shop.cloud.filter.CurrentUserId;
import com.shop.cloud.filter.MagicPermission;
import com.shop.cloud.service.system.IDictService;
import com.shop.cloud.util.Page;
import com.shop.cloud.util.Response;
import com.shop.cloud.util.ResponseUtil;

@RestController
@RequestMapping(value = "dict")
public class SysDictController extends BaseController {

	private static final Logger logger=Logger.getLogger(SysDictController.class);
	
	@Autowired
	private IDictService sysDictService;
	
	@MagicPermission
	@RequestMapping(value = "find", method = RequestMethod.POST)
	@ResponseBody
	public Response find(@CurrentUserId Long userId,HttpServletRequest request){
		Map<String, Object> params=getPageMap(request);
		Page<SysDict> datas=sysDictService.page(params);
		return ResponseUtil.ok(datas);
	}
	
	@MagicPermission
	@RequestMapping(value = "list", method = RequestMethod.POST)
	@ResponseBody
	public Response list(HttpServletRequest request){
		Map<String, Object> params=getPageMap(request);
		return ResponseUtil.ok(sysDictService.find(params));
	}
	
	@MagicPermission
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public Response update(HttpServletRequest request,SysDict sysDict){
		sysDictService.update(sysDict);
		return ResponseUtil.ok();
	}
	
	@MagicPermission
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody
	public Response add(HttpServletRequest request,SysDict sysDict){
		sysDict.setStatus("1");
		sysDictService.insert(sysDict);
		return ResponseUtil.ok();
	}

 	@MagicPermission
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public Response delete(@CurrentUserId Long userId,HttpServletRequest request){
		HashMap<String, Object> param=getParamMap(request);
		sysDictService.remove(param);
		return ResponseUtil.ok();
	}

}